﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace Charts.Converters
{
	[MarkupExtensionReturnType(typeof(IMultiValueConverter))]
	public abstract class MultiValueConverterBase<T> : MarkupExtension, IMultiValueConverter
		where T : class, new()
	{
		#region IMultiValueConverter members
		public abstract object Convert(object[] values, Type targetType, object parameter, CultureInfo culture);

		public virtual object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
		#endregion
		
		#region MarkupExtension members
		public override object ProvideValue(IServiceProvider serviceProvider)
		{
			if (converter == null)
				converter = new T();
			
			return converter;
		}
		
		private static T converter = null;
		#endregion
		
	}
}
